<template>
    <div class="abnormal-log-query edu-page-warp">
        <condition-card
            @reset="reset"
            @search="abnormalLogList"
            label-width="100px"
            label-position="right"
        >
            <!-- <span slot="other-btn" style="margin-left: 10px;">
                <el-button type="primary">高级查询</el-button>
            </span>-->
            <el-row>
                <el-col :span="8">
                    <el-form-item label="年级">
                        <el-date-picker
                            style="width: 100%;"
                            v-model="query.currentGrade"
                            type="year"
                            value-format="yyyy"
                            @change="handleChangeFaculty"
                            placeholder="请选择"
                            :picker-options="pickerOptions"
                        ></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学院">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.currentFaculty"
                            :data="options.currentFaculty"
                            @change="handleChangeFaculty"
                            filterable
                            multiple
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <!-- <el-col :span="8">
                    <el-form-item label="学位类型">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.degreeType"
                            :data="options.degreeType"
                            @change="handleChangeFaculty"
                        ></DictSelect>
                    </el-form-item>
                </el-col> -->
                <el-col :span="8">
                    <el-form-item label="培养专业">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.currentProfession"
                            :data="options.profession"
                            multiple
                        ></DictSelect>
                    </el-form-item>
                </el-col>
            </el-row>
            <!-- <el-row>
                <el-col :span="8">
                    <el-form-item label="培养层次">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.trainingLevel"
                            :data="options.trainingLevel"
                            multiple
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="培养类别">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.trainingCategory"
                            :data="options.trainingCategory"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                
            </el-row> -->
            <el-row>
                <!-- <el-col :span="8">
                    <el-form-item label="学习形式">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.formLearning"
                            :data="options.formLearning"
                        ></DictSelect>
                    </el-form-item>
                </el-col> -->
                
                <el-col :span="8">
                    <el-form-item label="异动大类">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.classId"
                            :data="options.abnormalCategories"
                            :clearable="false"
                            @change="handlerAbnormalCategories"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="异动类型">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.typeId"
                            :data="options.abnormalType"
                            :clearable="false"
                            @change="handlerAbnormalType"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="异动原因">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.reasonName"
                            :data="options.abnormalReason"
                            :clearable="false"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                
            </el-row>
            <el-row>
                
                <el-col :span="8">
                    <el-form-item label="异动时间">
                        <el-row type="flex" justify="center" align="middle">
                            <el-date-picker
                                v-model="query.abnormalStartTime"
                                value-format="timestamp"
                                type="date"
                                placeholder="选择日期"
                            ></el-date-picker>
                            <span style="margin: 0 10px;">~</span>
                            <el-date-picker
                                v-model="query.abnormalEndTime"
                                type="date"
                                value-format="timestamp"
                                placeholder="选择日期"
                            ></el-date-picker>
                        </el-row>
                    </el-form-item>
                </el-col>
                <!-- <el-col :span="8">
                    <el-form-item label="审核时间">
                        <el-row type="flex" justify="center" align="middle">
                            <el-date-picker
                                v-model="query.operateStartTime"
                                value-format="timestamp"
                                type="date"
                                placeholder="选择日期"
                            ></el-date-picker>
                            <span style="margin: 0 10px;">~</span>
                            <el-date-picker
                                v-model="query.operateEndTime"
                                type="date"
                                value-format="timestamp"
                                placeholder="选择日期"
                            ></el-date-picker>
                        </el-row>
                    </el-form-item>
                </el-col> -->
            </el-row>
        </condition-card>
        <el-card shadow="never">
            <h2 class="edu-page-title">异动到期名单</h2>
            <el-row type="flex" algin="middle" class="mb-8px">
                <el-col class="text-left">
                    <KeywordInput
                        v-model="query.keyWord"
                        @enter="abnormalLogList"
                        :placeholder="$t('score.failScoreManage.pleaseInt')"
                    ></KeywordInput>
                </el-col>
                <el-col class="text-right">
                    <el-button @click="exportLogList">导出</el-button>
                </el-col>
            </el-row>
            <edu-table
                :order="false"
                :data="logList.data"
                :total="logList.total"
                @page-change="pageChange"
                @selection-change="handleSelectionChange"
            >
                <el-table-column label="学号" show-overflow-tooltip>
                    <template slot-scope="scope">{{
                        scope.row.studentId
                    }}</template>
                </el-table-column>
                <el-table-column label="姓名" show-overflow-tooltip>
                    <template slot-scope="scope">
                        {{ scope.row.studentName }}
                    </template>
                </el-table-column>
                <el-table-column label="年级" show-overflow-tooltip>
                    <template slot-scope="scope">{{
                        scope.row.currentGrade
                    }}</template>
                </el-table-column>
                <el-table-column label="学院" show-overflow-tooltip>
                    <template slot-scope="scope">{{
                        scope.row.currentFacultyI18n
                    }}</template>
                </el-table-column>
                <el-table-column label="培养专业" show-overflow-tooltip>
                    <template slot-scope="scope">{{
                        scope.row.currentProfessionName
                    }}</template>
                </el-table-column>
                <el-table-column label="学籍专业" show-overflow-tooltip>
                    <template slot-scope="scope">{{
                        scope.row.statusProfessionName
                    }}</template>
                </el-table-column>
                <el-table-column label="异动类型" show-overflow-tooltip>
                    <template slot-scope="scope">{{
                        scope.row.typeName
                    }}</template>
                </el-table-column>
                <el-table-column label="异动开始时间" show-overflow-tooltip>
                    <template slot-scope="scope">{{
                        scope.row.abnormalStartTimeFormart
                    }}</template>
                </el-table-column>
                <el-table-column label="异动结束时间" show-overflow-tooltip>
                    <template slot-scope="scope">{{
                        scope.row.abnormalEndTimeFormart
                    }}</template>
                </el-table-column>
                <el-table-column label="异动原因" show-overflow-tooltip>
                    <template slot-scope="scope">{{
                        scope.row.reasonName
                    }}</template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" width="140">
                    <template slot-scope="scope">
                        <template>
                            <el-button
                              type="text"
                              @click="operate(scope.row, 1)"
                            >查看</el-button>
                        </template>
                    </template>
                </el-table-column>
            </edu-table>
        </el-card>
    </div>
</template>
<script>
import filters from "common/src/filters";
import { queryDic } from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import * as API from "common/src/api/abnormalType/abnormal";
import * as applyApi from "common/src/api/studentStatus/abnormalManage";
export default {
    name: "abnormalLogQuery",
    filters: {
        formatDate(date) {
            return filters.formatDate(date, "yyyy/MM/dd hh:mm:ss");
        }
    },
    data() {
        return {
            query: {
                currentGrade: "",
                currentFaculty: [],
                currentProfession: [],
                // trainingLevel: [],
                // trainingCategory: "",
                degreeType: "",
                formLearning: "",
                classId: "",
                typeId: "",
                reasonName: "",
                operateType: "",
                operateStartTime: "",
                operateEndTime: "",
                keyWord: "",
                pageNum_: 1,
                pageSize_: 20
            },
            students: [],
            options: {
                currentFaculty: [],
                profession: [],
                // trainingLevel: [],
                formLearning: [],
                degreeType: [],
                // trainingCategory: [],
                abnormalType: [],
                abnormalReason: [],
                leaveSchool: [],
                abnormalCategories: [],
                operateType: [
                    {
                        label: "申请",
                        value: "1"
                    },
                    {
                        label: "审核",
                        value: "2"
                    },
                    {
                        label: "撤销",
                        value: "3"
                    },
                    {
                        label: "驳回",
                        value: "4"
                    }
                ]
            },
            pickerOptions: {
                disabledDate(time) {
                    return (
                        time.getTime() > Date.now() ||
                        time.getTime() < new Date("1978").getTime()
                    );
                }
            },
            selectedItems: [],
            logList: {
                data: [],
                total: 0
            },
            studentIdList: null
        };
    },
    created() {
        this.initOptions();
        
        this.query.isStudent = this.$store.getters.getGlobal().isStudent;
        if (this.mockUser) {
            this.query.currentUuid = this.mockUser.uid;
        } else if (this.currentUser) {
            this.query.currentUuid = this.currentUser.uid;
        }
        this.abnormalLogList();
    },
    mounted() {},
    methods: {
        // 获取筛选条件字段下拉数据
        initOptions() {
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: [
                    "X_YX",
                    "X_PYCC",
                    "X_PYLB",
                    "X_XWLX",
                    "X_XXXS",
                    "K_ZXZT",
                    "G_XJDL"
                ]
            };
            queryDic(data).then(res => {
                if (res.code === 200) {
                    UTILS.fillSelect(
                        {
                            currentFaculty: "X_YX",
                            // trainingLevel: "X_PYCC",
                            // trainingCategory: "X_PYLB",
                            degreeType: "X_XWLX",
                            formLearning: "X_XXXS",
                            leaveSchool: "K_ZXZT",
                            abnormalCategories: "G_XJDL"
                        },
                        res.data,
                        this.options
                    );
                }
            });
        },
         // 根据学院获取专业
        handleChangeFaculty(val) {
            this.options.profession = [];
            this.query.currentProfession = [];
            let facultys, degreeType;
            facultys = this.query.currentFaculty;
            degreeType = this.query.degreeType ? [this.query.degreeType] : [];
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["G_ZY"],
                filter: {
                    prefix: facultys,
                    specilaCode: "XY2ZY",
                    facultys: facultys,
                    grade: this.query.currentGrade,
                    degreeType: degreeType
                }
            };
            queryDic(data).then(res => {
                if (res.code === 200)
                    UTILS.fillSelect(
                        {
                            profession: "G_ZY"
                        },
                        res.data,
                        this.options
                    );
                this.options.profession = this.options.profession.map((item) => {
                    return {
                        key: item.value,
                        label: item.label + "(" + item.value + ")",
                        value: item.value
                    }
                })
            });
        },
        // 异动大类改变时获取异动类型
        handlerAbnormalCategories(val) {
            this.query.typeId = "";
            this.query.reasonName = "";
            this.options.abnormalType = [];
            this.options.abnormalReason = [];
            API.getAbnormalTypeByClassCode(val).then(res => {
                let { code, data } = res;
                if (code === 200 && data) {
                    this.options.abnormalType = data;
                }
            });
        },
        // 异动类型改变获取异动原因
        handlerAbnormalType(val) {
            this.query.reasonName = "";
            this.options.abnormalReason = [];
            API.getAbnormalReason(val).then(res => {
                let { code, data } = res;
                if (code === 200 && data) {
                    data.forEach(item => {
                        this.options.abnormalReason.push({
                            label: item.reason,
                            value: item.id
                        });
                    });
                }
            });
        },
        operate(row, type) {
            let queryParams = {
                type: "abnormalManage",
                studentInfo: row
            };
              if (type == 1) {
                //queryParams添加一个参数 reviewVisiable判断进入审核页的入口，控制审核页审核理由模块显示
                queryParams.reviewVisiable = false;
                queryParams.type = "view";
                queryParams.comePage = "changeDueList";
                this.$router.push({
                    path: "/abnormalView",
                    query: queryParams
                });
            }  
        },
        // 重置
        reset() {
            this.query.currentGrade = "";
            this.query.currentFaculty = [];
            // this.query.trainingLevel = [];
            // this.query.trainingCategory = null;
            this.query.currentProfession = [];
            this.query.formLearning = "";
            this.query.classId = "";
            this.query.typeId = "";
            this.query.reasonName = "";
            this.query.abnormalStartTime = null
            this.query.abnormalEndTime = null
            this.query.keyWord = "";
            // Object.assign(this.$data, this.$options.data());
            this.initOptions();
            this.abnormalLogList();
        },
        // 查询异动日志
        async abnormalLogList() {
          /*debugger*/
            try {
                let params = _.cloneDeep(this.query);
                
                params.currentFaculty = params.currentFaculty + "";
                // params.trainingLevel = params.trainingLevel + "";
                params.currentProfession = params.currentProfession + "";
                if (this.options.abnormalType.length > 0) {
                  if (this.options.abnormalType.find(
                    e => e.value === params.typeId
                  )){
                    params.typeId =
                      this.options.abnormalType.find(
                        e => e.value === params.typeId
                      ).typeId;
                  } ;

                }
                let { code, data } = await applyApi.timeIsUpList(params);
                if (code == 200) {
                    let list = data.list ? data.list : [];
                     
                    this.logList.data = list;
                    this.logList.total = data.total_;
                }
            } catch (err) {
                console.log(err);
            }
        },
        pageChange(val) {
            this.query.pageNum_ = val.pageNum;
            this.query.pageSize_ = val.pageSize;
            this.abnormalLogList();
        },
        handleSelectionChange(val) {
            this.selectedItems = val;
        },
        // 导出异动日志列表
        exportLogList() {
            let params = _.cloneDeep(this.query);
            params.currentFaculty = params.currentFaculty + "";
            // params.trainingLevel = params.trainingLevel + "";
            if (this.options.abnormalType.length > 0) {
              if (this.options.abnormalType.find(
                e => e.value === params.typeId
              )){
                params.typeId =
                  this.options.abnormalType.find(
                    e => e.value === params.typeId
                  ).typeId;
              } ;

            }
            // 学生勾选数据处理
            if (this.selectedItems.length > 0) {
                let length = this.selectedItems.length;
                let ids = "";
                this.selectedItems.forEach((e, i) => {
                    if (length - 1 == i) {
                        ids += `${e.id}`;
                    } else {
                        ids += `${e.id},`;
                    }
                });
                params.ids = ids;
            } else {
                params.ids = "";
            }
            applyApi.exportClass("apply/timeIsUpXlsx", params);
        },
         
    },
     computed: {
        currentUser() {
            if (this.$store.state.session.user) {
                return this.$store.state.session.user;
            }
            return JSON.parse(localStorage.getItem("user"));
        },
        mockUser() {
            if (this.$store.state.session.mockUser) {
                return this.$store.state.session.mockUser;
            }
            let sessiondata = JSON.parse(localStorage.getItem("sessiondata"));
            if (sessiondata && sessiondata.mockUser) {
                return sessiondata.mockUser;
            }
        }
    }
};
</script>
<style lang="scss" scoped>
</style>
